package com.erp;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class HashMapTest2 {

    public static void main(String[] args) {

        Map<String, String> map = new HashMap<>();
        Map<String, String> map2 = Collections.synchronizedMap( map);
        Thread t1 = new Thread(() -> {
            for(int i = 0; i < 1000; i++) {
                map2.put(String.valueOf(i), String.valueOf(i));
            }
        });
        t1.start();

        Thread t2 = new Thread(() -> {
            for(int i = 1000; i < 2000; i++) {
                map2.put(String.valueOf(i), String.valueOf(i));
            }
        });
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(map2.size());
    }
}
